//
//  WBStatuesOriginalView.swift
//  weibo
//
//  Created by yanghong on 15/12/12.
//  Copyright © 2015年 杨鸿. All rights reserved.
//

import UIKit

class WBStatusesOriginalView: UIView {
    
    var statusViewModel: WBStatuedViewModel? {
        didSet{
            
            iconView.sd_setImageWithURL(NSURL(string: (statusViewModel?.status?.user?.profile_image_url)!), placeholderImage: UIImage(named: "avatar_default_big"))
            // 设置昵称
            nameLabel.text = statusViewModel?.status?.user?.name
            creatAtLabel.text = statusViewModel?.creatAtText
            sourceLabel.text = statusViewModel?.sourceText
            // 设置会员图标以及认证
            vipImg.image = statusViewModel?.vipImg
            verifiedView.image = statusViewModel?.verifiedImg
            
            // 设置原创微博内容
            contentLabel.text = statusViewModel?.status?.text
            
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func  setupUI() {
        
        //添加控件
        
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(creatAtLabel)
        addSubview(sourceLabel)
        addSubview(verifiedView)
        addSubview(vipImg)
        addSubview(contentLabel)
       
        
        //添加约束
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(WBStatusesCellMargin)
            make.leading.equalTo(self).offset(WBStatusesCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        //添加名字 nameLabel 约束
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(WBStatusesCellMargin)
            make.leading.equalTo(iconView.snp_trailing).offset(WBStatusesCellMargin)
        
        }
        // vipImg 约束
        
        vipImg.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(WBStatusesCellMargin)
            make.leading.equalTo(nameLabel.snp_trailing).offset(WBStatusesCellMargin)
            
        }
        // verifiedView 约束
        
        verifiedView.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(iconView.snp_bottom)
            make.centerX.equalTo(iconView.snp_trailing)
        }
        // creatAtLabel 约束
        creatAtLabel.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(iconView)
            make.leading.equalTo(nameLabel)
            
        }
        // sourceLabel 约束
        sourceLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(creatAtLabel)
            make.leading.equalTo(creatAtLabel.snp_trailing).offset(WBStatusesCellMargin)
        }
        //  contentLabel 约束
    
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(iconView)
            make.top.equalTo(iconView.snp_bottom).offset(WBStatusesCellMargin)
        }
        //  这个需要加上  才能自动计算出cell 的高度
        snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLabel).offset(WBStatusesCellMargin)
        }

    }
    // MARK -  懒加载控件
    //头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //名字的label
    private lazy var nameLabel: UILabel = {
        
        let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(14)
        
        return label
    }()
    // 时间的label
    private lazy var creatAtLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(10)
        return label
        
    }()
    //来源label
    private lazy var sourceLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(10)
        return label
        
    }()
    // 认证图标
    
    private lazy var  verifiedView: UIImageView = {
        
        let verifiedView = UIImageView()
        
        verifiedView.image = UIImage(named: "avatar_vip")
        
        return verifiedView
        
    }()
    //vip 图标
    private lazy var vipImg: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //微博内容
    
    // 微博内容
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        
        label.textColor = UIColor.darkGrayColor()
        
        label.font = UIFont.systemFontOfSize(15)
        
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = SCREENWIDTH - 2 * WBStatusesCellMargin
        return label
        
    }()
    
}
